import utils from "../../utils/index"
import siteinfo from "../../siteinfo"
import regeneratorRuntime from '../../libs/wxPromise.min';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: []
    },
    index: {
      type: Number,
      value: 0
    },
    width:{
      type:Number,
      value:100
    },
    color:{
      type:String,
      value:''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    offsetX: 0,
    offsetx:0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tabClick(e) {
      let {index} = e.currentTarget.dataset
      this.setData({
        index
      },()=>{
        this.queryInfo()
        this.triggerEvent('click',{index:index})
      })
    },
    queryInfo(){
      let _this = this
      const query = siteinfo.prefix.createSelectorQuery().in(this)
      let {index} = this.data
      query.select('.scroll-item.active').boundingClientRect(function (res) {
        let offsetx = res.width/2+(index*res.width)
        _this.setData({
          offsetx
        },()=>{
          console.log(_this.data.offsetx)
        })
      }).exec()
    }
  },
  lifetimes: {
    async ready() {
      let _this = this
      let {index} = this.properties
      const query = siteinfo.prefix.createSelectorQuery().in(this)
      query.select('.scroll-item.active').boundingClientRect(function (res) {
        let offsetx = res.width/2+(index*res.width)
        _this.setData({
          offsetx,
          sys:getApp().globalData.isIOS
        })
      }).exec()
    }
  }
})